/*
 * @Descripttion: 将收到的语音转发到前台显示
 * @version: 1.0
 * @Author: 自由如风
 * @Date: 2021-05-23 09:29:14
 * @LastEditors: 自由如风
 * @LastEditTime: 2021-05-23 15:45:33
 */

const { Plugin } = require('weixin-nodejs')
const { wss } = require('../index')

class ServerVoice extends Plugin {
    test() {
        return this.req.is('voice') && this.store.get('barrageRoom');// 判断是否有弹幕间
    }
    process() {
        // 组织数据
        const barrage = {
            avatar: this.store.get('user').headimgurl,
            content: this.req.voice.Recognition, // 需要开启语音识别
            openId: this.params.FromUserName
        }

        wss.sendBullet(this.store.get('barrageRoom'), barrage); // 发送
        return this.req.voice.Recognition;
    }
}

module.exports = ServerVoice;